package cn.com.haopy.dataes.mongodb.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * swagger在线文档配置<br>
 * 项目启动后可通过地址：http://host:ip/swagger-ui.html 查看在线文档
 *
 * @author enilu
 * @version 2018-07-24
 */

@Configuration
@EnableSwagger2
@EnableKnife4j
@ConditionalOnProperty(name = "swagger.production", havingValue = "false")
public class MongoDbSwagger2Configuration {
    @Bean
    public Docket esApiDocket() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                //.host("https://www.baidu.com")
                .apiInfo(adminApiInfo())
                .groupName("mongoApi")
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.com.haopy.dataes.mongodb.web"))
//                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build()
                .enableUrlTemplating(true)
                //.extensions(openApiExtensionResolver.buildExtensions(groupName))
                //.extensions(openApiExtensionResolver.buildSettingExtensions())
                //.globalOperationParameters(parameters)
                //.securityContexts(securityContexts).securitySchemes(securitySchemes);
                //.securityContexts(CollectionUtil.newArrayList(securityContext()))
                //.securitySchemes(CollectionUtil.newArrayList(apiKey()))
                ;
        return docket;
    }

    private ApiInfo adminApiInfo() {
        return new ApiInfoBuilder()
                .title("Haopy esApi ")
                .description("Happy esApi ")
                .termsOfServiceUrl("https://gitee.com/haopy/esApi")
                .version("1.0")
                .build();
    }
}
